package vip.xiaonuo.modular.controller;

import vip.xiaonuo.core.annotion.BusinessLog;
import vip.xiaonuo.core.annotion.Permission;
import vip.xiaonuo.core.enums.LogAnnotionOpTypeEnum;
import vip.xiaonuo.core.pojo.page.PageResult;
import vip.xiaonuo.core.pojo.response.ResponseData;
import vip.xiaonuo.core.pojo.response.SuccessResponseData;
import vip.xiaonuo.modular.entity.Zhuanye;
import vip.xiaonuo.modular.param.ZhuanyeParam;
import vip.xiaonuo.modular.service.ZhuanyeService;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.List;

/**
 * modular控制器
 *
 * @author 春非昔日春
 * @date 2023-03-08 17:33:57
 */
@Controller
public class ZhuanyeController {

    private String PATH_PREFIX = "zhuanye/";

    @Resource
    private ZhuanyeService zhuanyeService;

    /**
     * modular页面
     *
     * @author 春非昔日春
     * @date 2023-03-08 17:33:57
     */
    @Permission
    @GetMapping("/zhuanye/index")
    public String index() {
        return PATH_PREFIX + "index.html";
    }

    /**
     * modular表单页面
     *
     * @author 春非昔日春
     * @date 2023-03-08 17:33:57
     */
    @GetMapping("/zhuanye/form")
    public String form() {
        return PATH_PREFIX + "form.html";
    }

    /**
     * 查询modular
     *
     * @author 春非昔日春
     * @date 2023-03-08 17:33:57
     */
    @Permission
    @ResponseBody
    @GetMapping("/zhuanye/page")
    @BusinessLog(title = "modular_查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public PageResult<Zhuanye> page(ZhuanyeParam zhuanyeParam) {
        return zhuanyeService.page(zhuanyeParam);
    }

    /**
     * 添加modular
     *
     * @author 春非昔日春
     * @date 2023-03-08 17:33:57
     */
    @Permission
    @ResponseBody
    @PostMapping("/zhuanye/add")
    @BusinessLog(title = "modular_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData add(@RequestBody @Validated(ZhuanyeParam.add.class) ZhuanyeParam zhuanyeParam) {
        zhuanyeService.add(zhuanyeParam);
        return new SuccessResponseData();
    }

    /**
     * 删除modular
     *
     * @author 春非昔日春
     * @date 2023-03-08 17:33:57
     */
    @Permission
    @ResponseBody
    @PostMapping("/zhuanye/delete")
    @BusinessLog(title = "modular_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody @Validated(ZhuanyeParam.delete.class) List<ZhuanyeParam> zhuanyeParamList) {
        zhuanyeService.delete(zhuanyeParamList);
        return new SuccessResponseData();
    }

    /**
     * 编辑modular
     *
     * @author 春非昔日春
     * @date 2023-03-08 17:33:57
     */
    @Permission
    @ResponseBody
    @PostMapping("/zhuanye/edit")
    @BusinessLog(title = "modular_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData edit(@RequestBody @Validated(ZhuanyeParam.edit.class) ZhuanyeParam zhuanyeParam) {
        zhuanyeService.edit(zhuanyeParam);
        return new SuccessResponseData();
    }

    /**
     * 查看modular
     *
     * @author 春非昔日春
     * @date 2023-03-08 17:33:57
     */
    @Permission
    @ResponseBody
    @GetMapping("/zhuanye/detail")
    @BusinessLog(title = "modular_查看", opType = LogAnnotionOpTypeEnum.DETAIL)
    public ResponseData detail(@Validated(ZhuanyeParam.detail.class) ZhuanyeParam zhuanyeParam) {
        return new SuccessResponseData(zhuanyeService.detail(zhuanyeParam));
    }

    /**
     * modular列表
     *
     * @author 春非昔日春
     * @date 2023-03-08 17:33:57
     */
    @Permission
    @ResponseBody
    @GetMapping("/zhuanye/list")
    @BusinessLog(title = "modular_列表", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData list(ZhuanyeParam zhuanyeParam) {
        return new SuccessResponseData(zhuanyeService.list(zhuanyeParam));
    }

}
